import unittest 
from main.dataStructures import ProcessesQueue
from main.process import PCB ,  Instruction , Process

class TestDataStructures(unittest.TestCase):
    def setUp(self):
        self.pcb1 =  PCB(3)
        self.pcb2 =  PCB(6)
        self.pcb3 =  PCB(7)
        #
        self.instruction1 =  Instruction(1,1)
        self.instruction2 =  Instruction(2,2)
        self.instruction3 =  Instruction(2,3)
        self.instruction4 =  Instruction(1,4)
        self.instruction5 =  Instruction(2,5)
        self.instruction6 =  Instruction(1,6)
        self.instruction7 =  Instruction(2,7)
        self.instruction8 =  Instruction(1,8)
        self.instruction9 =  Instruction(1,9)
        self.instruction10=  Instruction(2,10)
        #
        self.process1 = Process(self.pcb1)#IO
        self.process1.addInstruction(self.instruction1)
        self.process1.addInstruction(self.instruction2)
        self.process1.addInstruction(self.instruction3)
        self.process1.addInstruction(self.instruction4)
        #
        self.process2 = Process(self.pcb2)#Cpu
        self.process2.addInstruction(self.instruction5)
        self.process2.addInstruction(self.instruction6)
        self.process2.addInstruction(self.instruction7)
        #
        self.process3 = Process(self.pcb3)#IO
        self.process3.addInstruction(self.instruction8)
        self.process3.addInstruction(self.instruction9)
        self.process3.addInstruction(self.instruction10)
        #
        self.processQueue = ProcessesQueue()
        #
        self.processQueue.append(self.process1)
        self.processQueue.append(self.process2)
        self.processQueue.append(self.process3)
        

    def test_appendProcessInProcessQueue(self):
        self.assertEquals(self.process1, self.processQueue.processes[0])
        self.assertEquals(3,len(self.processQueue.processes))
        
        
    def test_whenPopAprocessFromTheProcessQueue(self):
        x= self.processQueue.pop(0)
        self.assertEquals(self.process1,x)
        
        
    def test_lenghtFromTheProcessQueueAfterAddAprocess(self):
        x = self.processQueue.length()
        self.assertEquals(3,x)
        
        
    def test_getAprocessByItsIndex(self):
        x = self.processQueue.get(1)
        self.assertEquals(self.process2,x)
        
        
    def test_obtainIndexOfAProcessfromTheQueueProcess(self):
        x = self.processQueue.index(self.process1)
        self.assertEquals(x,0)
        
        
    def test_cutAprocessFromTheProcessesQueue(self):
        self.processQueue.cut(self.process2)  # ROMPIA PORQUE CUT NO TOMA INDEX, TOMA ELEMENTO
        self.assertEquals(2,len(self.processQueue.processes))
        self.assertFalse(self.processQueue.contains(self.process2))
        
        
        
suite = unittest.TestLoader().loadTestsFromTestCase(TestDataStructures)
unittest.TextTestRunner(verbosity=2).run(suite)

